﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string [] incoming=File.ReadAllLines("./..//..//in.txt");
            string s = incoming[0].ToString();
            string[] arrStr = s.Split(',');
            int[] arr = new int[arrStr.Length];
            for (int i = 0; i < arrStr.Length ; i++)
            {
                arr[i] = Convert.ToInt32(arrStr[i]);
            }
            int x = Convert.ToInt32(incoming[1]);
            int n = arr.Length - 1;
            int res=0;
            for (int j = 0; j <arr.Length; j++)
            {
                res = (int)(res + arr[j] * Math.Pow(x, (n-j)));
            }
            File.WriteAllText("./..//..//out.txt",res.ToString());

            
        }
    }
}
